package com.zbkj.crmeb.store.controller;


import com.common.CommonPage;
import com.crmeb.core.common.CommonResult;
import com.common.PageParamRequest;
import com.zbkj.crmeb.store.model.SupplierDiscount;
import com.zbkj.crmeb.store.request.AddDiscountRequest;
import com.zbkj.crmeb.store.service.SupplierDiscountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wuzp
 * @since 2021-09-25
 */
@RestController
@RequestMapping("api/admin/store/supplier/discount")
@Api(tags = "供应商服务")
public class SupplierDiscountController {

    @Autowired
    SupplierDiscountService supplierDiscountService;

    /**
     * 则扣列表
     */
    @ApiOperation(value = "创建折扣")
    @PostMapping(value = "/list")
    public CommonResult<CommonPage<SupplierDiscount>> getDiscountList(PageParamRequest pageParamRequest){
        return CommonResult.success(CommonPage.restPage(supplierDiscountService.getDiscountList(pageParamRequest)));
    }

    /**
     * 创建折扣
     */
    @ApiOperation(value = "创建折扣")
    @PostMapping(value = "/add")
    public CommonResult<String> addDiscount(@RequestBody @Validated AddDiscountRequest request){
        return supplierDiscountService.addDiscount(request) ? CommonResult.success() : CommonResult.failed();
    }

    /**
     * 编辑折扣
     */
    @ApiOperation(value = "编辑折扣")
    @PostMapping(value = "/update")
    public CommonResult<String> updateDiscount(@RequestBody @Validated AddDiscountRequest request){
        return supplierDiscountService.updateDiscount(request) ? CommonResult.success() : CommonResult.failed();
    }

    /**
     * 终止折扣
     */
    @ApiOperation(value = "终止折扣")
    @GetMapping(value = "/stop/{id}")
    public CommonResult<String> stopDiscount(@PathVariable("id") Integer id){
        return supplierDiscountService.stopDiscount(id) ? CommonResult.success() : CommonResult.failed();
    }

    /**
     * 删除折扣
     */
    @ApiOperation(value = "删除折扣")
    @DeleteMapping(value = "/delete/{id}")
    public CommonResult<String> deleteDiscount(@PathVariable("id") Integer id){
        return supplierDiscountService.deleteDiscount(id) ? CommonResult.success() : CommonResult.failed();
    }


}

